package split.panel;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;

import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JSlider;
import javax.swing.border.BevelBorder;
import javax.swing.border.SoftBevelBorder;

import org.apache.log4j.Level;

public class SpliWindow extends JFrame {
	final JSplitPane horizSplitPane;
	final BannerPanel bannerPanel;
	final LogPanel logPanel;
	LogTablePanel logTablePanel;
	final JPanel bottomPanel = new JPanel();
	
	static long stringNumber;
	protected JSlider slider = new JSlider();

	public SpliWindow() {
		super();
		setPreferredSize(new Dimension(800, 600));
		setMinimumSize(new Dimension(800, 600));
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		bannerPanel = new BannerPanel(this);
		logPanel = new LogPanel();
//		horizSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, bannerPanel, logTablePanel);
		logTablePanel =  new LogTablePanel(new LogTable());
		setSlider(slider);
		
//		bottomPanel.setLayout(new GridLayout(2, 0, 0, 0));
//		bottomPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0));
		bottomPanel.setLayout(new BorderLayout());
		
//		bottomPanel.add(slider, BorderLayout.PAGE_END);
////		add(btnNewButton_1, BorderLayout.NORTH);
//		bottomPanel.add(logTablePanel, BorderLayout.CENTER);
		
		bottomPanel.add(slider, BorderLayout.PAGE_START);
//		add(btnNewButton_1, BorderLayout.NORTH);
		bottomPanel.add(logTablePanel, BorderLayout.CENTER);
		
		horizSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, bannerPanel, bottomPanel);
		
		horizSplitPane.setOneTouchExpandable(true);
		horizSplitPane.setContinuousLayout(true);
		setContentPane(horizSplitPane);
		pack();
		horizSplitPane.setDividerLocation(0.8);
		
		setVisible(true);
	}
	
	private void setSlider(JSlider slider2) {
		slider2.setMinimum(1);
		slider2.setMaximum(6);
		slider2.setName("Logging Level");
		slider2.setFont(new Font("Dialog", Font.PLAIN, 12));
		slider2.setBorder(new SoftBevelBorder(BevelBorder.RAISED, null, null, null, null));
//		slider2.setMinorTickSpacing(1);
//		slider2.setMajorTickSpacing(2);
//		slider2.setPaintTicks(true);
//		slider2.setPaintTrack(false);
		
		Hashtable<Integer, JComponent> dict = new Hashtable<>();
		
		JLabel label = new JLabel("FATAL");
		System.out.println(label.getFont());
		label.setFont(new Font("Dialog", Font.PLAIN, 12));
		dict.put(1, label );
		dict.put(2, new JLabel(Level.ERROR.toString()));
		dict.put(3, new JLabel(Level.WARN.toString()));
		dict.put(4, new JLabel(Level.INFO.toString()));
		dict.put(5, new JLabel(Level.DEBUG.toString()));
		dict.put(6, new JLabel(Level.TRACE.toString()));
		slider2.setLabelTable( dict );

		
		slider2.setPaintLabels(true);
	}
	
	void appendString(){
		String[] toApend = new String[3];
		for(byte i=0; i<toApend.length; i++){
			toApend[i] = "String"+stringNumber++;
		}
		logTablePanel.append(toApend);
		
	}
}
